<%
'' This code is absolute freeware. you can do with it as you please. 
'' There are no restrictions what so ever, but the code is AS IS, no warrenty or liabilty
'' Please leave these commentlines intact
'' Netherlands, February 2004
'' M.Blokdijk
'' maarten@blokdijk.com
'' V 1.0

Sub CreateNewFolder
On error resume next
%>

<br /><b><%=traduci("ling_file_02")%></b><br /><br />
<%=traduci("ling_file_09")%> <%=spath%>
  <form method="post" action="<%=scriptname%>&amp;action=newfolder&amp;path=<%=sPath%>">
        
  <input name="folder" type="text" value="folder name" size="30" />

        <input type="submit" value="<%=traduci("ling_file_08")%>" name="submit" />
</form>
<br />
<%

End Sub

Sub EditFile
On error resume next
  Session("lastpage") = Request.ServerVariables("HTTP_REFERER")
  Set ReadStream = fs.OpenTextFile(server.mappath(sFile))
  filename=request.querystring("file")
  response.write ("<br />")  
  Response.write "currently editing: "
  response.write "<b>"&filename&"</b>"
  response.write "<br />"
  
  Response.Write "<form method=""POST"" action=""" & scriptname & "&action=savefile&path=" & sPath & "&file=" & Request.Querystring("File") & "&overwrite=yes"">" &vbCrLf
  Response.Write "<p><textarea rows=""20"" cols=""95"" name=""filestuff"">" & Server.HTMLEncode(ReadStream.ReadAll) & "</textarea></p>" &vbCrLf
response.write "Save file as: <input name=NewFileName type=text size=30>"
  Response.Write "<p><input type=""submit"" value=""Save changes"" name=""submit"">&nbsp;<input type=""reset"" value=""restore original"" name=""reset""></p>" &vbCrLf
  Response.Write "</form>" &vbCrLf 

  
End Sub

Sub UploadFiles
On error resume next
%>
<br /><%=traduci("ling_file_09")%><b> <%=spath%></b><br />
      <form method="post" action="admin.asp?modulo=content&amp;op=upload" enctype="multipart/form-data">
        <input type="file" name="FILE1" size="30" /><br />
		<input type="file" name="FILE2" size="30" /><br />
		<input type="file" name="FILE3" size="30" /><br />
		<input type="file" name="FILE4" size="30" /><br />
		<input type="file" name="FILE5" size="30" /><br />
		<input type="file" name="FILE6" size="30" /><br />
		<input type="file" name="FILE7" size="30" /><br />
		<input type="file" name="FILE8" size="30" /><br />
		<input type="file" name="FILE9" size="30" /><br />
		<input type="file" name="FILE10" size="30" /><br />
			<br />
        <input type="submit" value="<%=traduci("ling_file_17")%>" name="submit" />
      </form>
<%
End Sub



Sub CreateFile
On error resume next
  response.write "<br /><b>"&traduci("ling_file_03")&"</b><br />"
  Session("lastpage") = Request.ServerVariables("HTTP_REFERER") 
  Response.Write "<form method=""post"" action=""" & scriptname & "&amp;action=savefile&amp;path=" & sPath & """>" &vbCrLf
  Response.Write "<p><input type=""text"" name=""file"" />"&traduci("ling_file_10")&"</p>" &vbCrLf
  Response.Write "<input type=""submit"" style=""margin: 10px; position: relative"" value="""&traduci("ling_file_03")&""" name=""submit"" />" &vbCrLf  
  Response.Write "<p>"&traduci("ling_file_11")&"<br /><textarea style=""margin: 10px; width:90%; height: 180px;;"" name=""newfilestuff""></textarea></p><br />" &vbCrLf
  Response.Write "</form><br />" &vbCrLf
End Sub

Sub SaveFile
On error resume next
  '' the save as a new file routine
  if request.form("NewFileName")<>"" then
  NewFileName=request.form("NewFileName")
  spath=request("path")
    if spath="/" then slashvalue="" else slashvalue="/" end if
  filestuff=request.form("filestuff")
  NewPathFileName= spath&slashvalue&newfilename''creating the right path and filename
    Set fso = CreateObject("Scripting.FileSystemObject")
	Set textStreamObject = fso.CreateTextFile(server.mappath(NewPathFileName),true,false)
	textStreamObject.write filestuff
	Response.Redirect("" & Session("lastpage") & "")
  else
  '' done saving as routine

  If Request.Querystring("overwrite") = "si" Then
    fs.DeleteFile(server.mappath(server.mappath(sFile)))
	Set WriteFile = fs.CreateTextFile(server.mappath(sFile), true)
	WriteFile.Write Request.Form("filestuff")''filestuff''Session("filestuff")
    WriteFile.Close
	Response.Redirect("" & Session("lastpage") & "")
	
  Else
	Session("lastpage") = Request.ServerVariables("HTTP_Referer")
    If fs.FileExists(server.mappath(sFile)) Then
      Session("sFile") = sFile
	  spath=request.querystring("path")
      Session("newfilestuff") = Request.Form("newfilestuff")
      Response.Write "<br /><p>"&traduci("ling_file_12")&": <b>" & sFile & "</b> </p>"
      Response.Write "<ul>"
      Response.Write "<li><a href=""" & scriptname & "&amp;action=savenewfile&amp;overwrite=si"">"&traduci("ling_file_13")&"</a>"
      ' We don't want to lose the information that the typed in the previous form if they decide NOT to overwrite the existing file,
	  ' so we provide a javascript link back that works exactly the same as the browser's back button.
			Response.Write "<li><a href=""javascript:history.back()"">"&traduci("ling_file_14")&"</a></li>"
      Response.Write "</ul>"
    Else 
      Set WriteFile = fs.CreateTextFile(server.mappath(sFile), false)
      WriteFile.Write Request.Form("newfilestuff")
      WriteFile.Close
      Response.Redirect("admin.asp?modulo=content&op=filemanager&action=viewfolder&path="&spath&"")  
    End If
  End If
  end if
End Sub

Sub CreateFolder
On error resume next
 
 Session("lastpage") = request.querystring("path")
 If fs.FolderExists(server.mappath(sFolder)) Then 
   response.write "A folder with the name <b>" & sFolder & "</b> already exists<br />"  
 Else
   fs.CreateFolder(server.mappath(sFolder))
   ''Response.Redirect("" & Session("lastpage") & "")
response.redirect("admin.asp?modulo=content&op=filemanager&action=viewfolder&path="&session("lastpage")&"")


 End If
End Sub

Sub DeleteFile
On error resume next
	response.write"<br />"
  If Request.Querystring("commit") <> "yes" Then
    Session("lastpage") = Request.ServerVariables("HTTP_REFERER")
    Session("sFile") = sFile
    Response.Write "<p>" & traduci("ling_file_18") & sFile & ". " 
    If sFileType = "jpg" OR sFileType = "gif" or sFileType = "png" or sFileType = "bmp" Then
      Response.Write "<p><img src=""http://" & Request.ServerVariables("HTTP_HOST") & sfile & """ alt="""&sfile&""" /></p>"
    End If
    Response.Write "<b>" & traduci("ling_file_19") & "</b></p>"
    Response.Write "<ul>"
    Response.Write "<li><a href=""" & scriptname & "&amp;action=deletefile&amp;path=" & sPath & "&amp;file=" & sFile & "&commit=yes"">" & traduci("ling_file_20") & "</a></li>"
    Response.Write "<li><a href=" & Session("lastpage") & ">" & traduci("ling_file_04") & "</a></li>"
    Response.Write "</ul>"
  Else
    fs.DeleteFile(server.mappath(Session("sFile")))
    Response.Redirect("" & Session("lastpage") & "")
  End If
End Sub

Sub DeleteFolder
On error resume next
	response.write"<br />"
  If Request.Querystring("commit") <> "yes" Then 
    Session("lastpage") = Request.ServerVariables("HTTP_REFERER")
    Session("sFolder") = sFolder
    Response.Write "<p>You are about to delete: " & sFolder & ". " 
    Response.Write "<b>This cannot be undone!</b></p>"
    Response.Write "<UL>"
    Response.Write "<LI><a href=""" & scriptname & "&action=deletefolder&path=" & sPath & "&amp;folder=" & sFolder &  "&commit=yes"">Continue?</a></LI>"
    Response.Write "<LI><a href=" & Session("lastpage") & ">Stop</a></LI>"
    Response.Write "</UL>"
  Else
    Response.Write sPath & "<br />"
    Response.Write sFile & "<br />"
    fs.DeleteFolder(server.mappath(Session("sFolder")))
    Response.Redirect("" & Session("lastpage") & "")
  End If
End Sub

Sub RenameFolder

On error resume next
	response.write"<br />"
	Response.write "<b>Rename folder</b><br />"
  If Request.querystring("commit") <> "yes" Then 
    Session("lastpage") = Request.ServerVariables("HTTP_REFERER")
    Response.Write "<p>You are about to rename the folder named: <b>" & request.querystring("folder") & "</b>" 
%>
<form name="form1" method="post" action="default.asp?action=RenameFolder&path=<%=spath%>&folder=<%=request.querystring("folder")%>&commit=yes">
  <input name="NewFolderName" type="text" size="30">
  <input type="submit" name="Submit" value="Rename Folder">
  <input type="hidden"name="folder" value="<%=request.querystring("folder")%>">
</form>
<%
  Else
	NewFolderName=request.form("NewFolderName")
	sFolder=request.form("folder")
	if spath="/" then slashvalue="" else slashvalue="/" end if
    Set fso = CreateObject("Scripting.FileSystemObject")
	Set folderObject = fso.GetFolder(Server.MapPath(spath&slashvalue&sFolder))
	FolderObject.Name=NewFolderName
	 Set folderObject = Nothing
	 Set fso = Nothing
	  Response.Redirect("" & Session("lastpage") & "") 
   End If
  
End Sub

Sub RenameFile
On error resume next
  response.write"<br />"
  Response.write "<b>"&traduci("ling_file_15")&"</b><br />"
  If Request.QueryString("commit") <> "si" Then 
    Session("lastpage") = Request.ServerVariables("HTTP_REFERER")
    Response.Write "<p>"&traduci("ling_file_21")&"<b>" & request.querystring("file") & "</b></p>" 
%>
<form name="form1" method="post" action="admin.asp?modulo=content&amp;op=filemanager&amp;action=RenameFile&amp;path=<%=spath%>&amp;folder=<%=request.querystring("folder")%>&amp;commit=si">
  <input name="NewFileName" type="text" size="30" />
  <input type="submit" name="Submit" value="<%=traduci("ling_file_15")%>" />
  <input type="hidden" name="filename" value="<%=request.querystring("file") %>" />
</form>
  <%
  Else
  	NewFileName=request.form("NewFileName")
	Sfile=request.form("filename")
	if spath="/" then slashvalue="" else slashvalue="/"
    Set fso = CreateObject("Scripting.FileSystemObject")
	Set FileObject = fso.GetFile(Server.MapPath(spath&slashvalue&sfile))
	FileObject.Name = NewFileName
	Set FilObject = Nothing
	Set fso = Nothing
    Response.Redirect("" & Session("lastpage") & "")  
  End If
  
End Sub

Sub FileTypeUnsupported

End Sub

Sub Size(itemsize)
  Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom"">" &vbCrLf
  Select case Len(itemsize)
  Case "1", "2", "3" 
    Response.Write itemsize & " bytes"
  Case "4", "5", "6"
    Response.Write Round(itemsize/1000) & " Kb"
  Case "7", "8", "9"
    Response.Write Round(itemsize/1000000) & " Mb"
  End Select
  Response.Write "</td>" &vbCrLf
End Sub

Sub ShowList
 	' Start building the table to display the information we retrieve about the files and folders in the current directory.  
  %>
 
  <table id="listfile" cellpadding="0" cellspacing="0">
  <thead>
	  <tr>
		<td class="head" height="25"><%=traduci("ling_file_26")%></td>
		<td class="head" height="25"><div align="center"><%=traduci("ling_file_27")%></div></td>
		<td class="head" height="25"><div align="center"><%=traduci("ling_file_28")%></div></td>
		<td class="head" height="25"><div align="center"><%=traduci("ling_file_29")%></div></td>
		<td class="head" height="25"><div align="center"><%=traduci("ling_file_30")%></div></td>
	  </tr>
  </thead>
  <tbody>
  <%
  
    ' Use the GetFolder method of the filesystemobject to get the contents of the directory specified in sPath  
  Set fileobject = fs.GetFolder(server.mappath(sPath))
	' Use the SubFolders property to get the folders contained in the directory specified in sPath
  Set foldercollection = fileobject.SubFolders 
    ' Start the code to alternate line colors - just to make the display a little less visually confusing.
  lineid=0
  bgcolor = ""
    bgcolor_off = "#FFFFFF"
    bgcolor_on = "#f0f0f0"
  session("totSize") = 0
  ' Loop through the folders contained in the foldercollection and display their information on the page
  For Each folder in foldercollection 
    ' Apply our alternating line coloring
    If lineid = 0 Then
      bgcolor = bgcolor_off
      lineid = 1
    Else
      bgcolor = bgcolor_on
      lineid = 0
    End if		

		Response.Write "<tr bgcolor=""" & bgcolor & """>" &vbCrLf
		If Right(sPath,1)="/" Then
	    Response.Write "<td bgcolor=""" & bgcolor & """ align=""left"" valign=""bottom""><img alt="""&folder.name&""" src=themes/MODULI_IMG/MODULO_CONTENT/folder.gif /> <a href=""" & scriptname & "&amp;action=viewfolder&amp;path=" & sPath & folder.name & """>" & folder.name & "</a></td>" & vbCrLf

		Else
		  Response.Write "<td bgcolor=""" & bgcolor & """ align=""left"" valign=""bottom""><img alt="""&folder.name&""" src=themes/MODULI_IMG/MODULO_CONTENT/folder.gif /> <a href=""" & scriptname & "&amp;action=viewfolde&amp;path=" & sPath &"/" &folder.name & """>" & folder.name & "</a></td>" & vbCrLf

		End If  

	  Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom"">folder" 

Call Size(folder.size)
session("totSize") = session("totSize") + folder.size
	  Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom"">" & folder.datelastmodified & "</td>" &vbCrLf
	  Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom""><a href=""" & scriptname & "&amp;action=RenameFolder&amp;path=" & sPath & "&amp;folder=" & folder.name & """><img border=0 alt=rename src=themes/MODULI_IMG/MODULO_CONTENT/rename.gif /></a> <a href=""" & scriptname & "&amp;action=deletefolder&amp;path=" & sPath & "&amp;folder=" & folder.name & """><img border=0 alt=delete src=themes/MODULI_IMG/MODULO_CONTENT/delfolder.gif /></a></td>" &vbCrLf
    Response.Write "</tr>" &vbCrLf
  Next 
  Set foldercollection=nothing

  ' Use the Files property to get the files contained in the directory specified in sPath
  Set filecollection = fileobject.Files
  

	' Loop through the files contained in the filescollection and dislay their information on the page
	For Each file in filecollection 
	
    ' Apply our alternating line coloring
    If lineid = 0 Then
      bgcolor = bgcolor_off
      lineid = 1
    Else
      bgcolor = bgcolor_on
      lineid = 0
    End if	
    Response.Write "<tr>" &vbCrLf  
%>
  <%
	if fs.GetExtensionName(file.name)="gif" then image="<img alt=""gif"" src=themes/MODULI_IMG/MODULO_CONTENT/gif.gif />"
	if fs.GetExtensionName(file.name)="pdf" then image="<img alt=""pdf"" src=themes/MODULI_IMG/MODULO_CONTENT/pdf.gif />"
	if fs.GetExtensionName(file.name)="css" then image="<img alt=""css"" src=themes/MODULI_IMG/MODULO_CONTENT/css.gif />"
	if fs.GetExtensionName(file.name)="doc" then image="<img alt=""doc"" src=themes/MODULI_IMG/MODULO_CONTENT/word.gif />"
	if fs.GetExtensionName(file.name)="xls" then image="<img alt=""xls"" src=themes/MODULI_IMG/MODULO_CONTENT/xls.gif />"
	if fs.GetExtensionName(file.name)="exe" then image="<img alt=""exe"" src=themes/MODULI_IMG/MODULO_CONTENT/exe.gif />"
	if fs.GetExtensionName(file.name)="zip" then image="<img alt=""zip"" src=themes/MODULI_IMG/MODULO_CONTENT/zip.gif />"
	if fs.GetExtensionName(file.name)="jpg" then image="<img alt=""jpg"" src=themes/MODULI_IMG/MODULO_CONTENT/jpg.gif />"
	if fs.GetExtensionName(file.name)="jpeg" then image="<img alt=""jpeg"" src=themes/MODULI_IMG/MODULO_CONTENT/jpg.gif />"
	if fs.GetExtensionName(file.name)="htm" then image="<img alt=""htm"" src=themes/MODULI_IMG/MODULO_CONTENT/htm.gif />"
	if fs.GetExtensionName(file.name)="html" then image="<img alt=""html"" src=themes/MODULI_IMG/MODULO_CONTENT/htm.gif />"
	if fs.GetExtensionName(file.name)="swf" then image="<img alt=""swf"" src=themes/MODULI_IMG/MODULO_CONTENT/swf.gif />"
	if fs.GetExtensionName(file.name)="png" then image="<img alt=""swf"" src=themes/MODULI_IMG/MODULO_CONTENT/png.gif />"
	if fs.GetExtensionName(file.name)="asp" then image="<img alt=""asp"" src=themes/MODULI_IMG/MODULO_CONTENT/file.gif />"
	if fs.GetExtensionName(file.name)="txt" then image="<img alt=""txt"" src=themes/MODULI_IMG/MODULO_CONTENT/file.gif />"
	if fs.GetExtensionName(file.name)="inc" then image="<img alt=""inc"" src=themes/MODULI_IMG/MODULO_CONTENT/inc.gif />"
	if fs.GetExtensionName(file.name)="js" then image="<img alt=""js"" src=themes/MODULI_IMG/MODULO_CONTENT/js.gif />"
	if fs.GetExtensionName(file.name)="mdb" then image="<img alt=""mdb"" src=themes/MODULI_IMG/MODULO_CONTENT/mdb.gif />"
	
	if image="" then image= "<img alt=""unknown"" src=themes/MODULI_IMG/MODULO_CONTENT/unknown.gif />"
''Response.Write "<td bgcolor=""" & bgcolor & """ align=""left"" valign=""bottom"">"&image&" <a href=""" & scriptname & "&action=editfile&path=" & sPath & "&file=" & file.name & "&filetype=" & Lcase(fs.GetExtensionName(file.name)) & """>" & file.name & "</a></td>" &vbCrLf
Response.Write "<td bgcolor=""" & bgcolor & """ align=""left"" valign=""bottom"">"&image&" <a target=new href=""" & sPath&"/" & file.name &""">" & file.name & "</a></td>" &vbCrLf
	image=""
		Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom"">" & fs.GetExtensionName(file.name) & "</td>" &vbCrLf
	  Call Size(file.size)
	  session("totSize") = session("totSize") + file.size
	  Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom"">" & file.datelastmodified & "</td>" &vbCrLf
	  Response.Write "<td bgcolor=""" & bgcolor & """ align=""center"" valign=""bottom""><a href=""" & scriptname & "&amp;action=RenameFile&amp;path=" & sPath & "&amp;file=" & file.name & "&amp;filetype=" & Lcase(fs.GetExtensionName(file.name)) & """><img border=0 src=themes/MODULI_IMG/MODULO_CONTENT/rename.gif alt="""&traduci("ling_file_15")&""" /></a> <a href=""" & scriptname & "&amp;action=deletefile&amp;path=" & sPath & "&amp;file=" & file.name & "&amp;filetype=" & Lcase(fs.GetExtensionName(file.name)) & """><img border=0 src=themes/MODULI_IMG/MODULO_CONTENT/delfile.gif alt="""&traduci("ling_file_16")&""" /></a></td>" &vbCrLf
    Response.Write "</tr>" &vbCrLf
  Next

  ' We are done displaying information about files and folders in this directory, so close the table.
  Response.Write "</tbody></table>" &vbCrLf


End Sub


Sub DisplayErrors
	select case errornum
		case 1:
			response.Write "<p class=""errore"" style=""text-align:center"">" & traduci("ling_file_24") & "</p>"
		case 2:
			response.Write "<p class=""errore"" style=""text-align:center"">" & traduci("ling_file_25") & "</p>"
		case 3:
			response.Write "<p class=""errore"" style=""text-align:center"">" & traduci("ling_file_31") & "</p>"
	end select
End Sub

Sub nospace
		response.Write "<p class=""errore"" style=""text-align:center"">" & traduci("ling_file_23") & "</p>"
End Sub
%>


